package com.example.practice;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.design.widget.NavigationView;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;


public class SuccessActivity extends AppCompatActivity implements View.OnClickListener {

    private ImageView toolT;
    private TextView toolP;
    private Toolbar toolbar;
    private FrameLayout homePage;
    private ImageView scT;
    private Button scSetting;
    private Button scOut;
    private NavigationView navigationView;
    private DrawerLayout drawer;
    private FragmentManager fm;
    private FragmentTransaction ft;
    private ActionBarDrawerToggle toggle;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.activity_succes);
        fm = getSupportFragmentManager();
        initView();
        ui();

    }

    private void ui() {
        setSupportActionBar(toolbar);
        toggle = new ActionBarDrawerToggle(SuccessActivity.this, drawer, toolbar, 0, 0);
        drawer.addDrawerListener(toggle);
        getSupportActionBar().setDisplayShowTitleEnabled(false);
        toggle.syncState();
        Intent intent = getIntent();
        int sss = intent.getIntExtra("sss", 0);
        if(sss==1){ft = fm.beginTransaction();
        ft.replace(R.id.home_page, new Fragment_7());
        toolP.setText("实时显示");
        ft.commit();}
//        Window window = getWindow();
//        window.setFlags(
//                WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS,
//                WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
            @Override
            public boolean onNavigationItemSelected(@NonNull MenuItem menuItem) {
                switch (menuItem.getItemId()){
                    case R.id.single_1:
                        ft = fm.beginTransaction();
                        ft.replace(R.id.home_page, new Fragment_1());
                        toolP.setText("个人中心");
                        drawer.closeDrawers();
                        menuItem.setChecked(true);
                        ft.commit();
                        break;
                    case R.id.single_2:
                        ft = fm.beginTransaction();
                        ft.replace(R.id.home_page, new Fragment_2());
                        toolP.setText("红绿灯管理");
                        menuItem.setChecked(true);
                        drawer.closeDrawers();
                        ft.commit();
                        break;
                    case R.id.single_3:
                        ft = fm.beginTransaction();
                        ft.replace(R.id.home_page, new Fragment_3());
                        toolP.setText("我的账户");
                        menuItem.setChecked(true);
                        drawer.closeDrawers();
                        ft.commit();
                        break;
                    case R.id.single_4:
                        ft = fm.beginTransaction();
                        ft.replace(R.id.home_page, new Fragment_4());
                        toolP.setText("账户管理");
                        menuItem.setChecked(true);
                        drawer.closeDrawers();
                        ft.commit();
                        break;
                    case R.id.single_5:
                        ft = fm.beginTransaction();
                        ft.replace(R.id.home_page, new Fragment_5());
                        toolP.setText("车辆违章");
                        menuItem.setChecked(true);
                        drawer.closeDrawers();
                        ft.commit();
                        break;
                    case R.id.single_6:
                        ft = fm.beginTransaction();
                        ft.replace(R.id.home_page, new Fragment_6());
                        toolP.setText("环境指标");
                        menuItem.setChecked(true);
                        drawer.closeDrawers();
                        ft.commit();
                        break;
                    case R.id.single_7:
                        ft = fm.beginTransaction();
                        ft.replace(R.id.home_page, new Fragment_7());
                        toolP.setText("实时显示");
                        menuItem.setChecked(true);
                        drawer.closeDrawers();
                        ft.commit();
                        break;
                    case R.id.single_8:
                    ft = fm.beginTransaction();
                    ft.replace(R.id.home_page, new Fragment_8());
                    toolP.setText("阈值设置");
                    menuItem.setChecked(true);
                    drawer.closeDrawers();
                    ft.commit();
                    break;
                    case R.id.single_9:
                        ft = fm.beginTransaction();
                        ft.replace(R.id.home_page, new Fragment_Busq());
                        toolP.setText("公交查询");
                        menuItem.setChecked(true);
                        drawer.closeDrawers();
                        ft.commit();
                        break;
                    case R.id.single_10:
                        ft = fm.beginTransaction();
                        ft.replace(R.id.home_page, new CarwzFragment());
                        toolP.setText("车辆违章");
                        menuItem.setChecked(true);
                        drawer.closeDrawers();
                        ft.commit();
                        break;
                    case R.id.single_11:
                        ft = fm.beginTransaction();
                        ft.replace(R.id.home_page, new RoadFragment());
                        toolP.setText("路况查询");
                        menuItem.setChecked(true);
                        drawer.closeDrawers();
                        ft.commit();
                        break;
                    case R.id.single_12:
                        ft = fm.beginTransaction();
                        ft.replace(R.id.home_page, new LifeFragment());
                        toolP.setText("生活助手");
                        menuItem.setChecked(true);
                        drawer.closeDrawers();
                        ft.commit();
                        break;
                }
                return false;
            }
        });

    }

    private void initView() {
        toolP = (TextView) findViewById(R.id.tool_p);
        toolbar = (Toolbar) findViewById(R.id.toolbar);
        homePage = findViewById(R.id.home_page);
        scT = (ImageView) findViewById(R.id.sc_t);
        scSetting = (Button) findViewById(R.id.sc_setting);
        scOut = (Button) findViewById(R.id.sc_out);
        navigationView = (NavigationView) findViewById(R.id.navigation_view);
        scSetting.setOnClickListener(this);
        scOut.setOnClickListener(this);
        drawer = (DrawerLayout) findViewById(R.id.drawer);
        drawer.setOnClickListener(this);
    }


    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.sc_setting:

                break;
            case R.id.sc_out:

                break;
        }
    }
}
